﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)

        {
          
            String connectionstring = "Server=.;uid=sa;pwd=12345678;database=Djjj";
            SqlConnection sqlConnection = new SqlConnection(connectionstring);
            try
            {
                
                sqlConnection.Open();
                string sql = "select * from xxx";
                SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
                SqlDataReader nhz;
                nhz = sqlCommand.ExecuteReader();
                Console.WriteLine(nhz.FieldCount);
              
                Console.WriteLine(nhz.GetDataTypeName(0));
                
                string xty = "age";
                Console.WriteLine(nhz.GetOrdinal(xty));
                if (nhz.Read())
                    Console.WriteLine(nhz.GetValue(1));
                object[] myobj = new object[nhz.FieldCount];
                nhz.GetValues(myobj);
                while (nhz.Read())
                {
                    nhz.GetValues(myobj);
                    foreach (object outobj in myobj) Console.Write(outobj + "\t");
                    Console.WriteLine();

                }

                if (nhz.HasRows)
                {
                    Console.WriteLine(" xxx中存在数据");
                }
                else
                {
                    Console.WriteLine(" xxx中不存在数据");
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message.ToString());

            }
            finally
            {
                sqlConnection.Close();

            }
        }
    }
}
